<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery UI 拖动（Draggable） - 约束运动</title>
  <!--
  <link rel="stylesheet" href="//apps.bdimg.com/libs/jqueryui/1.10.4/css/jquery-ui.min.css">
  -->
  <link rel="stylesheet" href="jquery-ui-1.10.4.custom/css/base/jquery-ui-1.10.4.custom.css">
  <script src="//apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script>
 <!--
 <script src="//apps.bdimg.com/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
 --> 
  <script src="jquery-ui-1.10.4.custom/js/jquery-ui-1.10.4.custom.js"></script>
  <link rel="stylesheet" href="jqueryui/style.css">
  <style>
  .draggable { width: 90px; height: 90px; padding: 0.5em; float: left; margin: 0 10px 10px 0; }
  #draggable, #draggable2 { margin-bottom:20px; }
  #draggable { cursor: n-resize; }
  #draggable2 { cursor: e-resize; }
  #containment-wrapper { width: 95%; height:150px; border:2px solid #ccc; padding: 10px; }
  h3 { clear: left; }
  </style>
  <script>
  $(function() {
    $( "#draggable" ).draggable({ axis: "y" });
    $( "#draggable2" ).draggable({ axis: "x" });
 	$( "#draggable5" ).draggable({ containment: "parent" });
  
    $( "#draggable3" ).draggable({ 
    	//边框限制
    	containment: "#containment-wrapper", 
    	scroll: false ,//滚动限制
    	//鼠标限制
    	cursor: "move", //样式
    	cursorAt: { top: 56, left: 56 },//位置
    	//延迟
    	distance: 20,//像素延迟
    	delay: 1000,//时间延迟
    	//回调函数
        start: function() {//开始拖拽时调用
        	
        },
      drag: function() {//正在拖拽时调用
      },
      stop: function() {//结束后调用
      },
    //还原
     revert: true, //还原
     helper: "clone",  //克隆
    	
    	
    });
    
  });
  function ff(){
  	console.log(11111111)
  }
  function aa(){
  	console.log("aaaa")
  }
  </script>
</head>
<body>
 
<h3>沿着轴约束运动：</h3>
 
<div id="draggable" class="draggable ui-widget-content">
  <p>只能垂直拖拽</p>
</div>
 
<div id="draggable2" class="draggable ui-widget-content">
  <p>只能水平拖拽</p>
</div>
 
<h3>或者在另一个 DOM 元素中约束运动：</h3>
<div id="containment-wrapper">
  <div onclick="aa()" id="draggable3" class="draggable ui-widget-content">
    <p onclick="ff()">我被约束在盒子里</p>
  </div>
 
  <div class="draggable ui-widget-content">
    <p id="draggable5" class="ui-widget-header">我被约束在父元素内</p>
  </div>
</div>
 
 
</body>
</html>